package servlet;

import dao.OrdersDao;
import dao.impl.OrdersDaoImpl;
import pojo.Orders;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


/*
* 订单完成时做标注
* */
@WebServlet(urlPatterns = "/bus_finishServlet.do")

public class bus_finishServlet extends HttpServlet {
    private static OrdersDao ordersDao=new OrdersDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        int length=(int)req.getAttribute("orders_length");
//        List<Orders> orderList = (List<Orders>)req.getAttribute("orderList");
        List<Orders> orderList = (List<Orders>)getServletContext().getAttribute("ordersList");
        System.out.println(orderList);
        for (Orders order:orderList) {
            String key=String.valueOf(order.getOrd_no());
            System.out.println(key);
            String status = req.getParameter("order" + key);
            if (status!=null && status.equals("on")){
                ordersDao.finishOrder(order.getOrd_no());
            }
        }
        req.getRequestDispatcher("login.html").forward(req,resp);
    }
}
